#ifndef _VEC2D
#define _VEC2D

#include <math.h>

class vec2D
{
public:
	vec2D() {x = 0;		y = 0;}

	vec2D(const vec2D &_v1, const vec2D &_v2)
	{
		x = _v2.x - _v1.x;
		y = _v2.y - _v1.y;
	}

	vec2D(const float _x, const float _y) : x(_x), y(_y) {}

	float dot(const vec2D vec) {return (x * vec.x) + (y * vec.y);}

	void add(const vec2D & v, float dt)
	{
		if (dt == 0.f)
		{
			x += v.x;
			y += v.y;
		}
		else
		{
			x += v.x * dt;
			y += v.y * dt;
		}
	}

	void scale(const float coeff)
	{
		x *= coeff;
		y *= coeff;
	}

	void normalize()
	{
		float dist = norme();
		x = x / dist;
		y = y / dist;
	}

	float norme()
	{
		// N(a) = sqrt(ax² + ay²)
		return sqrt(pow(x,2) + pow(y,2));
	}

	float x;
	float y;
};

inline vec2D normalize(vec2D v)
{
	float dist = v.norme();
	v.x = v.x / dist;
	v.y = v.y / dist;
	return v;
}

#endif
